import 'package:flutter/material.dart';

import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:wanxiang_app/utils/common.dart';
import 'package:get/get.dart';
import '../bean/goods_detail_entity.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
typedef void ClickCallBack(String content);
class MyGalleryDialog extends Dialog {
  final int defaultIndex ;
  final List<GoodsDetailDataAlbums> galleryItems;
  final state;
  final controller;
  int nowIndex =0;
  MyGalleryDialog({required this.defaultIndex,required this.galleryItems ,required this.state,this.controller} );

  @override
  Widget build(BuildContext context) {

    onPageChanged(int a){

      state(() {
        nowIndex = a;
      });
    }
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            height: 300.h,
              width: Get.width,
              child: PhotoViewGallery.builder(
                scrollPhysics: const BouncingScrollPhysics(),
                builder: (BuildContext context, int index) {
                  return PhotoViewGalleryPageOptions(
                    imageProvider: NetworkImage(Common.realPicPath(galleryItems[index].originalPath) ),
                    initialScale: PhotoViewComputedScale.contained * 0.8,
                    heroAttributes: PhotoViewHeroAttributes(tag: galleryItems[index].id),
                  );
                },
                loadingBuilder: (context, event)=>Container(
                  height: 20.h,
                  width: 100.w,
                  color: Colors.red,
                  child: Text('1111111111111',style: TextStyle(color: Colors.white),),
                ),
                itemCount: galleryItems.length,
                // loadingBuilder: (context, event) => Center(
                //   child: Container(
                //       child:Text(
                //         '111111111111111111111',style: TextStyle(color: Colors.white),)
                //   ),
                // ),
                backgroundDecoration:  BoxDecoration(color: Colors.black12),
                pageController:  PageController(initialPage: defaultIndex),
                onPageChanged: onPageChanged,
              )
          ),
          // Text(
          //   (nowIndex+1).toString()+'/'+galleryItems.length.toString(),style: TextStyle(color: Colors.white),)
        ],
      ),
    )  ;
  }


}